# coding= utf-8

import sys
import codecs
import warnings
import pymongo

sys.stdout = codecs.getwriter('utf-8')(sys.stdout.detach())
warnings.filterwarnings("ignore")


class Compare:

    def __init__(self):
        # self.month = sys.argv[1]
        self.month = '2024-09'

        # 连接MongoDB
        self.myclient = pymongo.MongoClient("mongodb://localhost:27017/")
        mydb = self.myclient["xp_analyse"]
        self.low_order = mydb["wt_low_order"]
        self.low_order_v2 = mydb["wt_low_order_v2"]
        self.low_test = mydb["wt_low_test"]

    # 比较两个月中不一样的数据
    def compare_month_data(self):
       for v2 in self.low_order_v2.find({"month": self.month}):
            # 查询在low_order中是否存在该组asin国家对应关系
            exist = self.low_order.find_one({"asin": v2.get('asin'), "month": self.month, "group_name": v2.get('group_name'), "country_desc": v2.get('country_desc')})
            if not exist:
                self.low_test.insert(v2)
                self.low_order.insert(v2)
                print(self.month + '-' + v2.get('asin') + '-' + v2.get('group_name') + v2.get('country_desc') + '，不存在关系，已补充！')


compare = Compare()
compare.compare_month_data()
